#ifndef PICTUREMODEL_H
#define PICTUREMODEL_H

#include "gallery_core_global.h"
#include "picture.h"

#include <QAbstractListModel>

#include <vector>
#include <memory>

class Album;
class DatabaseManager;
class AlbumModel;

class GALLERY_CORESHARED_EXPORT PictureModel : public QAbstractListModel
{
    Q_OBJECT
public:
    enum PictureRoles {
        UrlRole = Qt::UserRole + 1,
        FilePathRole
    };

public:
    PictureModel(const AlbumModel& albumModel, QObject* parent = nullptr);

public:
    QModelIndex addPicture(const Picture& picture);

    void setAlbumId(int albumId);
    void clearAlbum();

public:
    int rowCount(const QModelIndex& parent = QModelIndex()) const override;
    QVariant data(const QModelIndex& index, int role) const override;
    bool removeRows(int row, int count, const QModelIndex& parent) override;

public slots:
    void deletePictureForAlbum();

private:
    void loadPicture(int albumId);
    bool isIndexValid(const QModelIndex& index) const;

private:
    DatabaseManager& mDb;
    int mAlbumId;
    std::unique_ptr<std::vector<std::unique_ptr<Picture>>> mPictures;
};

#endif // PICTUREMODEL_H
